<template>
  <div style="min-height: 500px">
    <el-button
      v-if="this.list.evalTaskId && this.row.progress >= 0 && row.evalMode !== 2"
      class="fr mb20"
      @click="startEval(list, 'evaluate')"
      type="primary"
    >开始考评</el-button>
    <e-table :tableData="tableData" :columns="columns" :loading="loading" :pageObj="null">
      <el-table-column slot="state" label="状态" width="80px" align="center">
        <template slot-scope="scope">
          <el-tag :type="judgeType(scope.row.taskState)">{{ judgeState(scope.row.taskState) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column slot="executorTime" label="执行时间" width="150" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.executorTime ? formatTime(scope.row.executorTime) : null }}</template>
      </el-table-column>
      <el-table-column slot="submitTime" label="提交时间" width="150" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.submitTime ? formatTime(scope.row.submitTime) : null }}</template>
      </el-table-column>
      <el-table-column slot="picture" label="执行图片" width="150" align="center">
        <template slot-scope="scope">
          <template v-if="scope.row.savePath">
            <img width="100%" v-viewer :src="scope.row.savePath" alt="图片" />
          </template>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column slot="sign" label="执行签名" width="150" align="center">
        <template slot-scope="scope">
          <template v-if="scope.row.executorSignature">
            <img width="100%" v-viewer :src="scope.row.executorSignature" alt="图片" />
          </template>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column slot="eventList" label="事件数" width="70" align="center">
        <template slot-scope="scope">{{ scope.row.evalTaskEventList.length }}</template>
      </el-table-column>
      <el-table-column slot="scoreRate" label="得分率" width="70" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.planTotalScore ? ( scope.row.planScore / scope.row.planTotalScore ) * 100 + '%' : '--%' }}</template>
      </el-table-column>
      <el-table-column slot="taskState" label="是否提交" width="80" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.taskState ? ((scope.row.taskState === 0 || scope.row.taskState === 1) ? '未提交' : '已提交') : '未提交' }}</template>
      </el-table-column>
      <el-table-column fixed="right" slot="action" label="操作" width="60" align="center">
        <template slot-scope="scope" v-if="scope.row.executorTime">
          <a @click="startEval(scope.row, 'detail')">详情</a>
        </template>
      </el-table-column>
    </e-table>
  </div>
</template>

<script>
import { startEval } from '@/api/eval'

import { getSession, setSession, judgeEvalState, judgeType, formatY } from '@/utils/util'

export default {
  props: {
    list: {
      type: Object
    }
  },
  watch: {
    list: {
      handler(n, o) {
        console.log('list new', n)
      }
    }
  },
  created() {
    this.tableData = this.list.evalDetailedList
  },
  data() {
    return {
      loading: false,
      columns: [
        {
          label: '部门',
          prop: 'name'
        },
        { slot: 'executorTime' },
        {
          label: '总分',
          prop: 'planTotalScore'
        },
        {
          label: '得分',
          prop: 'planScore'
        },
        { slot: 'scoreRate' },
        {
          label: '奖惩总额',
          prop: 'planMoney'
        },
        { slot: 'eventList' },
        { slot: 'picture' },
        { slot: 'taskState' },
        { slot: 'submitTime' },
        {
          label: '执行人',
          prop: 'executorUser'
        },

        { slot: 'sign' },
        {
          label: '考评签名',
          prop: 'targetSignature'
        },
        { slot: 'action' }
      ],
      tableData: [],
      row: this.$route.params.row || getSession('evalListRow')
    }
  },
  methods: {
    handleStartEval() {},
    judgeType(num) {
      return judgeType(num)
    },
    judgeState(num) {
      return judgeEvalState(num)
    },
    startEval(row, type) {
      console.log('传递row', row)

      this.$router.push({
        name: 'evaluateStartTest',
        params: { row, type }
      })
    }
  }
}
</script>
